<?php

namespace app\index\controller\landing;

use app\index\model\UM as UM;
use app\index\service\OptionalService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * Optional 控制器
 * Class Optional
 * @package app\index\controller\landing;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 * @see \app\index\validate\landing\Optional
 */
class Optional
{
    // 请求参数
    private Request $request;

    // service
    private OptionalService $service;

    public function __construct(Request $request, OptionalService $optionalService)
    {
        $this->request = $request;
        $this->service = $optionalService;
    }

    /**
     * 可选题列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /landing/optional/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $categoryId = $request->param('categoryId');
        
        return ApiResponse::success($this->service->index($user, $categoryId));
    }

}
